import request from '@/config/axios'
import { Sku, Spu } from '@/api/mall/product/spu'

// 赠品活动 VO
export interface PresentActivityVO {
  id: number // 活动编号
  name: string // 赠品活动名称
  spuId: number // 商品 SPU ID
  skuId: number //SKU ID
  totalLimitCount: number // 总限购数量
  singleLimitCount: number // 单次限购数量
  startTime: Date // 开始时间
  endTime: Date // 结束时间
  marketPrice:string
  status: number // 活动状态：0开启 1关闭
  limitDuration: number // 限制时长（小时）
  products: PresentActivityVO[]
}
// 扩展 Sku 配置
export type SkuExtension = Sku & {
  productConfig: PresentActivityVO
}

export interface SpuExtension extends Spu {
  skus: SkuExtension[] // 重写类型
}

// 赠品活动 API
export const PresentActivityApi = {
  
  // 查询赠品活动分页
  getPresentActivityPage: async (params: any) => {
    return await request.get({ url: `/promotion/present-activity/page`, params })
  },

  // 查询赠品活动详情
  getPresentActivity: async (id: number) => {
    return await request.get({ url: `/promotion/present-activity/get?id=` + id })
  },

  // 新增赠品活动
  createPresentActivity: async (data: PresentActivityVO) => {
    return await request.post({ url: `/promotion/present-activity/create`, data })
  },

  // 修改赠品活动
  updatePresentActivity: async (data: PresentActivityVO) => {
    return await request.put({ url: `/promotion/present-activity/update`, data })
  },

  // 删除赠品活动
  deletePresentActivity: async (id: number) => {
    return await request.delete({ url: `/promotion/present-activity/delete?id=` + id })
  },

  
// 关闭拼团活动
closePresentActivity : async (id: number) => {
  return await request.get({ url: '/promotion/present-activity/close?id=' + id })
},


  // 导出赠品活动 Excel
  exportPresentActivity: async (params) => {
    return await request.download({ url: `/promotion/present-activity/export-excel`, params })
  }
}
 